<template>
  <div class="init_main">
    <p class="name_sty">{{ name }}</p>
    <div class="query">
      任务名称：
      <el-input
        v-model="query.input"
        placeholder=""
        size="mini"
        style="width: 150px"
      ></el-input>
      质控类型：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="全部" value="全部"> </el-option>
      </el-select>
      模板组：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="全部" value="全部"> </el-option>
      </el-select>
      检查组：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="全部" value="全部"> </el-option>
      </el-select>
      <p></p>
      周期：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="全部" value="全部"> </el-option>
      </el-select>
      年份：
      <el-select v-model="query.value" placeholder="" size="mini">
        <el-option label="全部" value="全部"> </el-option>
      </el-select>
      机构：
      <el-cascader
        size="mini"
        :options="OrganTree"
        :props="{
          checkStrictly: true,
          value: 'Id',
          label: 'Name',
          children: 'Children',
        }"
        clearable
        v-model="checkHospitalId"
        @change="
          query.filter.checkHospitalId =
            checkHospitalId[checkHospitalId.length - 1]
        "
      ></el-cascader>
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="warning"
        @click="open_dialog('修改')"
        >修改</el-button
      > -->
      <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="del_row"
        >删除</el-button
      >
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
      >
        <el-table-column prop="Name" label="任务名称"> </el-table-column>
        <el-table-column prop="" label="进度">
          <template slot-scope="scope">
            {{ scope.row.DoneCount }} / {{ scope.row.InvestigatorCount }}
          </template>
        </el-table-column>
        <el-table-column prop="CheckSectionName" label="调查科室">
        </el-table-column>
        <el-table-column prop="TemplateGroupName" label="模板组">
        </el-table-column>
        <el-table-column prop="TemplateName" label="模板名称">
        </el-table-column>
        <el-table-column prop="InvestigatorCount" label="调查份数">
        </el-table-column>
        <el-table-column prop="StartTime" label="开始时间"> </el-table-column>
        <el-table-column prop="EndTime" label="结束时间"> </el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.CurrentPage"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div>
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <table border="1" style="width: 100%">
        <tr>
          <td class="tac">任务名称：</td>
          <td colspan="3">
            <el-input size="mini" v-model="form.Name"></el-input>
          </td>
        </tr>
        <tr>
          <td class="tac">模板组：</td>
          <td>
            <el-select
              v-model="form.templateGroupId"
              placeholder=""
              size="mini"
              style="width: 100%"
              @change="get_option_2"
            >
              <el-option
                v-for="item in 模板组"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              >
              </el-option>
            </el-select>
          </td>
          <td class="tac">模板名称：</td>
          <td>
            <el-select
              v-model="form.templateId"
              placeholder=""
              size="mini"
              style="width: 100%"
            >
              <el-option
                v-for="item in 版本组"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              >
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="tac">开始日期：</td>
          <td>
            <el-date-picker
              v-model="form.startTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              size="small"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </td>
          <td class="tac">结束日期：</td>
          <td>
            <el-date-picker
              v-model="form.endTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              size="small"
              placeholder="选择日期"
              style="width: 100%"
            >
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td class="tac">调查科室：</td>
          <td>
            <el-select
              v-model="form.checkSectionId"
              size="mini"
              style="width: 100%"
              placeholder="请选择"
              @change="GetAllUserListBySectionId"
            >
              <el-option
                v-for="item in ksList"
                :key="item.Id"
                :label="item.Name"
                :value="item.Id"
              >
              </el-option>
            </el-select>
          </td>
          <td class="tac">调查份数：</td>
          <td>
            <el-input size="mini" v-model="form.investigatorCount"></el-input>
          </td>
        </tr>
        <tr>
          <td class="tac">调查者：</td>
          <td>
            <el-select
              v-model="form.MydDiaoChaUserId"
              placeholder=""
              size="mini"
              style="width: 100%"
              @change="user_change"
              filterable
            >
              <el-option
                v-for="item in 被调查者"
                :key="item.UserId"
                :label="item.Name"
                :value="item.UserId"
              >
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="tac">机构：</td>
          <td colspan="3">
            <el-cascader
              style="width: 100%"
              size="mini"
              :options="OrganTree"
              :props="{
                checkStrictly: true,
                value: 'Id',
                label: 'Name',
                children: 'Children',
              }"
              clearable
              v-model="checkHospitalId"
              @change="
                form.checkHospitalId =
                  checkHospitalId[checkHospitalId.length - 1]
              "
            ></el-cascader>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        CurrentPage: 1,
        pageSize: 10,
        total: 0,
        filter: {
          SystemCategory: "门诊满意度",
          checkHospitalId: window.localStorage.getItem("hospitalId"),
          menuName: "满意度设置",
        },
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: null,
      form: {
        checkHospitalId: window.localStorage.getItem("hospitalId"),
      },
      模板组: [],
      质控组: [],
      版本组: [],
      OrganTree: [],
      checkHospitalId: window.localStorage.getItem("hospitalId"),
      ksList: [],
      被调查者: [],
    };
  },
  mounted() {
    this.name = this.$route.meta.title;
    this.getOptions();
    this.getList();
    this.getOrgan();
    this.getks();
  },
  filters: {
    toStatus(val) {
      var str = "";
      if (val == 0) {
        str = "未发布";
      }
      if (val == 1) {
        str = "开始调查";
      }
      if (val == 10) {
        str = "继续调查";
      }
      if (val == 20) {
        str = "待提交";
      }
      if (val == 30) {
        str = "已提交";
      }
      if (val == 31) {
        str = "原因分析";
      }
      if (val == 32) {
        str = "病区跟踪检查";
      }
      if (val == 33) {
        str = "护理部跟踪检查";
      }
      if (val == 40) {
        str = "完成";
      }
      if (val == 41) {
        str = "审核通过";
      }
      if (val == 42) {
        str = "归档";
      }
      return str;
    },
  },
  methods: {
    GetAllUserListBySectionId(val) {
      console.log(this.info);
      this.$post(
        "/Bs/GetAllUserListBySectionId?sectionId=" +
          val +
          "&SystemCategory=满意度"
      ).then((res) => {
        this.被调查者 = res.Data;
      });
    },
    getks() {
      this.$get("/Bs/GetSectionList").then((res) => {
        this.ksList = res.Data;
      });
    },
    getOrgan() {
      this.$get(
        "/Task/GetOrganTree?id=" + window.localStorage.getItem("hospitalId2")
      ).then((res) => {
        this.OrganTree = res.Data;
      });
    },
    getList() {
      this.$post("/Task/GetPageListRepsonse", this.query).then((res) => {
        this.tableData = res.Data.PageList;
        this.query.total = res.Data.Total;
      });
    },
    getOptions() {
      var query = {
        CurrentPage: 1,
        pageSize: 999,
        filter: {
          SystemCategory: "满意度调查",
        },
      };
      this.$post("/TemplateGroup/GetPageList", query).then((res) => {
        this.模板组 = res.Data.PageList;
      });
      this.$post("/CheckGroup/GetPageList", query).then((res) => {
        this.质控组 = res.Data.PageList;
      });
    },
    get_option_2(id) {
      var body = {
        currentPage: 1,
        pageSize: 999,
        filter: {
          hasDisable: true,
          orderByStr: "",
          groupId: id,
        },
      };
      this.$post("/Template/GetPageList", body).then((res) => {
        this.版本组 = res.Data.PageList;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = null;
        return;
      }
      this.row_info = row;
    },
    del_row() {
      this.$get("/Task/SoftDelete/" + this.row_info.Id).then((res) => {
        this.getList();
      });
    },
    handleClose() {
      (this.form = {
        checkHospitalId: window.localStorage.getItem("hospitalId"),
      }),
        (this.checkHospitalId = []);
      this.dialogVisible = false;
    },
    btn_ok() {
      this.form.SystemCategory = "门诊满意度";
      this.$post("/Task/Create", this.form).then((res) => {
        this.getList();
        this.handleClose();
      });
    },
    open_dialog(val) {
      this.dialog_title = val + "任务";
      if (val == "新增") {
        this.dialogVisible = true;
        return;
      }
      if (val == "修改" && this.row_info) {
        this.form = this.row_info;
        this.dialogVisible = true;
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.query.CurrentPage = 1;
    },
    handleCurrentChange_page(val) {
      this.query.CurrentPage = val;
      this.getList();
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
</style>